package view.main;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

import constants.GUIConstants;
import constants.Icons;
import controller.CompleteListener;


import view.BaseComponent;


public class FilePanel extends BaseComponent implements ActionListener {

	private JButton open;
	private JButton save;
	private JButton close;
	
	private JButton screen;
	private JButton movie;
	
	private JButton about;
	
	public FilePanel() {
		open = new JButton(Icons.getIcon("open"));
		save = new JButton(Icons.getIcon("save"));
		close = new JButton(Icons.getIcon("close"));
		screen = new JButton(Icons.getIcon("screen"));
		movie = new JButton(Icons.getIcon("movie"));
		about = new JButton(Icons.getIcon("about"));
		
		about.addActionListener(this);
		
		open.setActionCommand("open");
		save.setActionCommand("save");
		close.setActionCommand("close");
		screen.setActionCommand("screen");
		movie.setActionCommand("movie");
		about.setActionCommand("about");
		
		open.setMaximumSize(new Dimension(open.getIcon().getIconWidth()+4,
				open.getIcon().getIconHeight()+4));
		open.setPreferredSize(new Dimension(open.getIcon().getIconWidth()+4,
				open.getIcon().getIconHeight()+4));
		save.setMaximumSize(new Dimension(save.getIcon().getIconWidth()+4,
				save.getIcon().getIconHeight()+4));
		save.setPreferredSize(new Dimension(save.getIcon().getIconWidth()+4,
				save.getIcon().getIconHeight()+4));
		close.setMaximumSize(new Dimension(close.getIcon().getIconWidth()+4,
				close.getIcon().getIconHeight()+4));
		close.setPreferredSize(new Dimension(close.getIcon().getIconWidth()+4,
				close.getIcon().getIconHeight()+4));
		screen.setMaximumSize(new Dimension(screen.getIcon().getIconWidth()+4,
				screen.getIcon().getIconHeight()+4));
		screen.setPreferredSize(new Dimension(screen.getIcon().getIconWidth()+4,
				screen.getIcon().getIconHeight()+4));
		movie.setMaximumSize(new Dimension(movie.getIcon().getIconWidth()+4,
				movie.getIcon().getIconHeight()+4));
		movie.setPreferredSize(new Dimension(movie.getIcon().getIconWidth()+4,
				movie.getIcon().getIconHeight()+4));
		about.setMaximumSize(new Dimension(about.getIcon().getIconWidth()+4,
				about.getIcon().getIconHeight()+4));
		about.setPreferredSize(new Dimension(about.getIcon().getIconWidth()+4,
				about.getIcon().getIconHeight()+4));
		
		this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
		this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
		
		JSeparator sep = new JSeparator(SwingConstants.VERTICAL);
		sep.setMaximumSize(new Dimension(5,999999));
		JSeparator sep2 = new JSeparator(SwingConstants.VERTICAL);
		sep2.setMaximumSize(new Dimension(5,999999));
		
		this.add(open);
		this.add(Box.createHorizontalStrut(3));
		this.add(save);
		this.add(Box.createHorizontalStrut(3));
		this.add(close);
		this.add(Box.createHorizontalStrut(5));
		this.add(sep);
		this.add(Box.createHorizontalStrut(5));
		this.add(screen);
		this.add(Box.createHorizontalStrut(3));
		this.add(movie);
		this.add(Box.createHorizontalStrut(5));
		this.add(sep2);
		this.add(Box.createHorizontalStrut(5));
		this.add(about);
		this.add(Box.createHorizontalGlue());
	}

	@Override
	public void attachListener(CompleteListener l) {
		open.addActionListener(l);
		save.addActionListener(l);
		close.addActionListener(l);
		screen.addActionListener(l);
		movie.addActionListener(l);
	}

	@Override
	public void setEnabled(boolean enable) {
		open.setEnabled(enable);
		save.setEnabled(enable);
		close.setEnabled(enable);
		screen.setEnabled(enable);
		movie.setEnabled(enable);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("about"))
			JOptionPane.showMessageDialog(this, new JLabel(
					"<html><center><font color=#FF0000>St"+
					"<font color=#FF4400>ra"+
					"<font color=#FF7700>tT" +
					"<font color=#FFAA00>im" +
					"<font color=#FFCC00>er" +
					" "+GUIConstants.VERSION+"</font><br>"+
					"by Na" +
					"</font>G" +
					"</font>a" +
					"</font>sH<br><br>"+
					"<font color=#008800>An openSource project.</font>"));
	}
	
}
